
<?php
/**
 * eg:http://192.168.33.10/CI/index.php/client_control/add
 * 
 * 参见user_control.php,该文件参考自其中
 * 
 * 功能描述：
 * 	  实现推荐客户
 *  


 * 
 * 
 */


if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Client_Control extends CI_Controller {

	
	
	
	/**
	 * $this->load->view('jjr/block/header',$header_data);
		$this->load->view('jjr/index',$data);
		$this->load->view('jjr/block/footer');
	 */
	public function add(){
		$this->load->helper('url');
		
		$this->config->load('_myconfig.php');
		$debug = $this->config->item('mydebug');
		
		
		$header_data['title']=$this->config->item('mytitle');;
		$header_data['showdebug']=$this->config->item('showdebug');
		
		
		$id = isset($_POST['id'])?$_POST['id']:0;
		$cid = isset($_POST['cid'])?$_POST['cid']:0;
		$uid = isset($_POST['uid'])?$_POST['uid']:0;
		
		$creator = $uid;
		$name = isset($_POST['name'])?str_replace(' ', '', $_POST['name']):'';
		$comName = isset($_POST['comName'])?str_replace(' ', '', $_POST['comName']):'';
		$name = isset($_POST['name'])?str_replace(' ', '', $_POST['name']):'';
		
		$province = isset($_POST['province'])?$_POST['province']:'';
		$city = isset($_POST['city'])?$_POST['city']:'';
		$area = isset($_POST['area'])?$_POST['area']:'';
		$provinceId = isset($_POST['provinceId'])?$_POST['provinceId']:'';
		$cityId = isset($_POST['cityId'])?$_POST['cityId']:'';
		$areaId = isset($_POST['areaId'])?$_POST['areaId']:'';

		$gmsbType = isset($_POST['gmsbType'])?$_POST['gmsbType']:'';
		$gmTimeType = isset($_POST['gmTimeType'])?$_POST['gmTimeType']:'';
		$wjjpp = isset($_POST['wjjpp'])?$_POST['wjjpp']:'';
		$zzjpp = isset($_POST['zzjpp'])?$_POST['zzjpp']:'';
		$memo = isset($_POST['memo'])?$_POST['memo']:'';
		
		$_accountId = isset($_POST['uid'])?$_POST['uid']:0;  // 前台采用缓存中的userID
		$phone = isset($_POST['phone'])?str_replace(' ', '', $_POST['phone']):'';
		
		$owner = isset($_POST['owner'])?$_POST['owner']:0;
		$created = isset($_POST['created'])?$_POST['name']:time();
		$modified = $created;
		
		$state = isset($_POST['state'])?$_POST['state']:0;
		$flag = isset($_POST['flag'])?$_POST['flag']:0;	// 1:为提交态
		$_id= isset($_POST['_id'])?$_POST['_id']:0;  // phone's id
		$_created = isset($_POST['_created'])?$_POST['_created']:time();
		$_state = isset($_POST['_state'])?$_POST['_state']:0;
		
		if($uid==0)
			$flag=999;

		$client = array("id"=>$id , "name"=>$name , "provinceId"=>$provinceId , "cityId"=>$cityId , "areaId"=>$areaId , "city"=>$city , "province"=>$province , 
				"area"=>$area , "comName"=>$comName , "owner"=>$owner , "creator"=>$creator , "created"=>$created , "modified"=>$modified , "gmsbType"=>$gmsbType , 
				"gmTimeType"=>$gmTimeType , "wjjpp"=>$wjjpp , "zzjpp"=>$zzjpp , "memo"=>$memo , "state"=>$state , "flag"=>$flag);
		
		$client_phone = array("id"=>$_id,"accountId"=>$_accountId ,"phone"=>$phone ,"created"=>$_created ,"state"=>$_state);
		
		
		$data['title']='推荐客户';
		$data['cid']=$cid;
		$data['uid']=$uid;
		
		$client['creator']=$uid;
		$data['client']=$client;
		$data['client_phone']=$client_phone;
		
		$this->load->view('jjr/block/header',$header_data);
		if($flag==0){	
// 			print_r($data);
			$this->load->view('jjr/client1',$data); // 推荐一
			$this->load->view('jjr/block/footer');
			
		}
		
//		if($flag==1){	// 推荐一提交
//			// check 采用前台验证
//			$this->load->view('jjr/client2',$data); // 推荐二
//			$this->load->view('jjr/block/footer');
//			
//		}
		
		if($flag==2){	// 推荐到第二步
			$_state = isset($_POST['_state'])?$_POST['_state']:0;
			$this->load->model('client_model');
			$id = $this->client_model->add($data['client'],$data['client_phone']);
			$data['msg']="您已经成功推荐一个客户";
			$this->load->view('jjr/msg',$data);
			$this->load->view('jjr/block/footer');
		}
		
		if($flag==999){
			$data['msg']="请注册并等待审核通过";
			$this->load->view('jjr/msg',$data);
			
			$this->load->view('jjr/block/_footer');
	}
		
		
	}
	
	
	
	
	
	
	public function delete(){
		
		
		
		$cid = isset($_POST['cid'])?$_POST['cid']:0;
		
		
		$this->load->model('j_client');
		$this->j_client->client_delete(22);
	}
	
	

	public function update(){
		$this->load->model('j_client');
		$arr = array('usid'=>22,'uname'=>'deng222','upass'=>'1233333');
		$this->j_client->client_update(2,$arr);
	}

	

	
	
	
	
	public function select()
	{
		$this->load->model('j_client');
		$arr = $this->j_client->client_select(14);
		print_r($arr);
		echo $arr[0]->id;

	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */